<%@ page import="java.util.Enumeration,
                 java.util.Stack,
                 java.util.HashMap,
                 com.oval.util.OvalTools"%>
<%      /*
           \ufffd\u0436\ufffd\ufffd\u01f2\ufffd\ufffd\ufffd
        */
        String jsp_pageback_url =(String)request.getParameter(JSP_BACKPAGENAME);
			  String faflag ="";
			  if(request.getParameter("faflag")!=null){
			  	faflag=(String)request.getParameter("faflag");
			  
			  } 
        if(jsp_pageback_url!=null && !jsp_pageback_url.trim().equals("")){
                setPagebackParameter(request,session );
        }
        String  return_url = "top.left.page_back(self,'"+  request.getHeader("referer")+"&faflag="+faflag+"');" ;
       	
       	if(isNewMethodForPageBack(session)){
             return_url = "document.location.href=\""+ request.getContextPath() +"/Page_Back.jsp?" +OvalTools.randomURL() +"\";";
        
        }
%>
<script language="JavaScript">
 function  page_back(){
       <%=JspHelper.filterNull(return_url)%>
 }
</script>
<%!
     public  String   PAGE_BACK_SESSION  = "page_back_session";
     public  String    JSP_BACKPAGENAME  = "jsp_backpagename";

     public  void    setPagebackParameter(HttpServletRequest  request , HttpSession session ){
           Stack  pageBackParameterStack =(Stack) session.getAttribute(PAGE_BACK_SESSION);
           if(pageBackParameterStack==null){
                    pageBackParameterStack = new Stack();
           }
           HashMap   pageBackParameterHashMap  =  new HashMap();
           Enumeration parameterEnumeration = request.getParameterNames();

           while(parameterEnumeration.hasMoreElements()){
                String  parameterObject= parameterEnumeration.nextElement().toString();
                String  parameterValue = (String) request.getParameter(parameterObject) ;
                if(parameterObject.equals("pageaction") && (parameterValue==null  || parameterValue.trim().equals(""))){
                       parameterValue="OrderBy";
                }
                if(parameterValue!=null  && !parameterValue.trim().equals("")){
                        parameterValue = changeGBK(parameterValue );
                        pageBackParameterHashMap.put(parameterObject,parameterValue);  System.out.println(parameterObject +" = " +parameterValue);
                }
           }

           pageBackParameterStack.push(pageBackParameterHashMap);
           session.setAttribute(PAGE_BACK_SESSION,pageBackParameterStack);
     }

     public  boolean   isNewMethodForPageBack(HttpSession session){
          Stack  pageBackParameterStack =(Stack) session.getAttribute(PAGE_BACK_SESSION);
          if(pageBackParameterStack==null || pageBackParameterStack.isEmpty())    return   false ;

          HashMap   pageBackParameterHashMap =(HashMap) pageBackParameterStack.peek();
          if(pageBackParameterHashMap==null)      return  false ;

          String  jsp_pageback_url=(String)pageBackParameterHashMap.get(JSP_BACKPAGENAME);
          if(jsp_pageback_url==null || jsp_pageback_url.equals(""))     return false ;

          return  true ;
     }
     public  String   changeGBK(String  s ) {
               String  strTempGBK =null;

               try{
                     strTempGBK= new String(s.getBytes("ISO-8859-1"),"GBK");
               } catch (Exception e){

               }
               if(strTempGBK!=null)  {
                         s  = strTempGBK;
               }
          return  s ;
    }
%>
